from io import BytesIO
import pytesseract,requests
from PIL import Image

def get_verification_code():
    '''
    func:获取验证码
    :return:
    '''
    # 设置路径
    pytesseract.pytesseract.tesseract_cmd = r"D:\Tesseract-OCR\tesseract.exe"

    #获取验证码图片接口
    url='http://10.59.9.32/jeewms/randCodeImage'

    response=requests.get(url,stream=True)
    jsession_id=response.cookies.get('JSESSIONID')
    img=Image.open(BytesIO(response.content))
    code=pytesseract.image_to_string(img,config='--psm 7 -c tessedit_char_whitelist=0123456789').strip()
    return code,jsession_id

    # response=requests.get(url,stream=True)
    #
    # jsession_id = response.cookies.get('JSESSIONID')
    # img=Image.open(BytesIO(response.content))
    #
    # code=pytesseract.image_to_string(img,config='--psm 7 -c tessedit_char_whitelist=0123456789').strip()
    #
    # return code, jsession_id



